package recursion;

public class FeiBoNaQIShu {
    public static void main(String[] args) {
        //long k = h(30);//递归超过五十，计算量会非常大，不建议超过50
       // System.out.println(k);
        //用循环求斐波那契数
        System.out.println(l(64));
    }

    private static long h(int i) {
        if(i<=0){
            return -1;
        }
        if(i==1 || i==2){
            return 1;
        }
        return h(i-1)+h(i-2);
    }

    private static long l(int i){
        if(i<=0){
            return -1;
        }
        if(i==1 || i==2){
            return 1;
        }
        long start =1, end =1;
        for (int j = 3; j <=i ; j++) {
            end=start+end;
            start=end-start;
        }
        return  end;
    }
}
